﻿using System.Collections.Generic;
using System.Linq;
using Core.CSV;

namespace Game.Trade {
    public class TradeUtils {
        public static List<ISellable> TranslateConfigIntoThings(TBSellerConfig config) {
            List<ISellable> things = new List<ISellable>();
            things.AddRange(TranslateWeaons(config.Weapons));
            things.AddRange(TranslateWeaponEffects(config.WeaponEffects));

            return things;
        }


        public static List<Weapon> TranslateWeaons(string weaponsStr) {
            List<Weapon> weapons = new List<Weapon>();
            string[] weaponArr = weaponsStr.Split("_");
            for (int i = 0; i < weaponArr.Length; i++) {
                string[] weaponItem = weaponArr[i].Split("/");
                Weapon weapon = WeaponFactory.New(uint.Parse(weaponItem[0]));
                weapon.Num = int.Parse(weaponItem[1]);
                weapon.Cost = int.Parse(weaponItem[2]);
                weapons.Add(weapon);
            }
            return weapons;
        }

        public static List<WeaponEffect> TranslateWeaponEffects(string weaponEffectsStr) {
            List<WeaponEffect> weaponEffects = new List<WeaponEffect>();
            string[] weaponEffectArr = weaponEffectsStr.Split("_");
            for (int i = 0; i < weaponEffectArr.Length; i++) {
                string[] weaponItem = weaponEffectArr[i].Split("/");
                WeaponEffect weaponEffect = WeaponEffectFactory.New(uint.Parse(weaponItem[0]));
                weaponEffect.Num = int.Parse(weaponItem[1]);
                weaponEffect.Cost = int.Parse(weaponItem[2]);
                weaponEffects.Add(weaponEffect);
            }
            return weaponEffects;
        }
    }
}